<link rel="stylesheet" href="{__STATIC__Plugs}/layuimini/css/login.css">
<div class="main-body">
    <div class="login-main">
        <div class="login-top">
            <span>{:sysConf('title')}后台登录</span>
            <span class="bg1"></span>
            <span class="bg2"></span>
        </div>
        <form class="layui-form login-bottom" autocomplete="off">
            <div class="center">
                <div class="item">
                    <span class="icon icon-2"></span>
                    <input type="text" name="username" lay-verify="required" placeholder="请输入登录账号" maxlength="24"/>
                </div>

                <div class="item">
                    <span class="icon icon-3"></span>
                    <input type="password" name="password" lay-verify="required" placeholder="请输入密码" maxlength="20">
                    <span class="bind-password icon icon-4"></span>
                </div>

                <div id="validatePanel" class="item" style="width: 137px;">
                    <input type="text" name="captcha" placeholder="请输入验证码" maxlength="4">
                    <img id="refreshCaptcha" class="validateImg" src="{:url('login/verify')}"
                         onclick="this.src='{:url(\'verify\')}?math='+Math.random();">
                </div>

            </div>
            <!--            <div class="tip">-->
            <!--                <span class="icon-nocheck"></span>-->
            <!--                <span class="login-tip">保持登录</span>-->
            <!--                <a href="javascript:" class="forget-password">忘记密码？</a>-->
            <!--            </div>-->
            <div class="layui-form-item" style="text-align:center; width:100%;height:100%;margin:0px;">
                <button class="login-btn" lay-submit="" lay-filter="login">立即登录</button>
            </div>
        </form>
    </div>
</div>
<div class="footer">
    {:sysConf('copy')}
</div>
<script>
    layui.use(['form', 'jquery'], function () {
        var $ = layui.jquery,
            form = layui.form,
            layer = layui.layer;

        // 登录过期的时候，跳出ifram框架
        if (top.location != self.location) top.location = self.location;

        $('.bind-password').on('click', function () {
            if ($(this).hasClass('icon-5')) {
                $(this).removeClass('icon-5');
                $("input[name='password']").attr('type', 'password');
            } else {
                $(this).addClass('icon-5');
                $("input[name='password']").attr('type', 'text');
            }
        });

        $('.icon-nocheck').on('click', function () {
            if ($(this).hasClass('icon-check')) {
                $(this).removeClass('icon-check');
            } else {
                $(this).addClass('icon-check');
            }
        });

        // 进行登录操作
        form.on('submit(login)', function (data) {
            let index = layer.msg("登录中..", {icon: 16, shade: 0.5, time: 10000000});
            data = data.field;
            if (data.username == '') {
                layer.msg('用户名不能为空');
                return false;
            }
            if (data.password == '') {
                layer.msg('密码不能为空');
                return false;
            }
            if (data.captcha == '') {
                layer.msg('验证码不能为空');
                return false;
            }
            $.post("{:url('checkLogin')}", data, function (res) {
                layer.close(index);
                if (res.code == "{$result.success}") {
                    layer.msg(res.msg, {icon: 6, sahde: 0.5}, function () {
                        window.location.href = "{:url('index/index')}"
                    })
                } else {
                    layer.msg(res.msg, {icon: 5, shade: 0.5});
                }
            })
            return false;
        });
    });
</script>